package com.magnificent.atlantis.client.data.message.messages;

import com.magnificent.atlantis.client.data.configuration.ServerConfiguration;
import com.magnificent.atlantis.client.data.message.MessageType;
import com.magnificent.atlantis.common.entity.messages.ServerMessage;

import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.Date;
import java.util.List;

/**
 * User: Babanin
 * Date: 04.05.2009
 * Time: 22:06:46
 */
@XmlRootElement(name = "message")
public abstract class ClientMessage {
    protected int configurationId;
    protected MessageType messageType;

    protected Date sentDate;

    protected int userFromId;
    protected List<Integer> usersToIds;

    protected ClientMessage() {
    }

    protected ClientMessage(ServerMessage serverMessage, ServerConfiguration configuration) {
        this.sentDate = serverMessage.getSentDate();
        this.userFromId = serverMessage.getUserFromId();
        this.configurationId = configuration.getId();
        this.messageType = MessageType.INBOX;
    }

    @XmlAttribute()
    public int getConfigurationId() {
        return configurationId;
    }

    public void setConfigurationId(int configurationId) {
        this.configurationId = configurationId;
    }

    @XmlAttribute()
    public MessageType getMessageType() {
        return messageType;
    }

    public void setMessageType(MessageType messageType) {
        this.messageType = messageType;
    }

    @XmlAttribute()
    public Date getSentDate() {
        return sentDate;
    }

    public void setSentDate(Date sentDate) {
        this.sentDate = sentDate;
    }

    @XmlElement()
    public List<Integer> getUsersToIds() {
        return usersToIds;
    }

    public void setUsersToIds(List<Integer> usersToIds) {
        this.usersToIds = usersToIds;
    }

    @XmlAttribute()
    public int getUserFromId() {
        return userFromId;
    }

    public void setUserFromId(int userFromId) {
        this.userFromId = userFromId;
    }

    protected void copyDataTo(ServerMessage serverMessage) {
        serverMessage.setUserFromId(userFromId);
        serverMessage.setSentDate(new Date());
    }

    public abstract String getTitle();

    public abstract boolean isSystemMessage();

    public abstract ServerMessage toServerMessage();
}
